<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include_once 'MySqlDataAccessHelper.php';

/**
 * Description of Word
 *
 * @author Phuong Vu
 */
class Word {
    public $id;
    public $id_Lesson;
    public $engName;
    public $vietName;
    public $engEx;
    public $vietEx;
    public $audio;
    public $audioEx;
    public $picture;
    public $isLearned;

    function loadAllWords($idLesson) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();

            $sql = "select* from Word where ID_Lesson =" . $idLesson;
            $result = $connection->executeQuery($sql);
            $listWord = array();
            while ($row = mysql_fetch_array($result)) {
                $temp = new Word();
                $temp->audio = $row['audio'];
                $temp->id_Lesson = $row['id_Lesson'];
                $temp->engName = $row['engName'];
                $temp->vietName = $row['vietName'];
                $temp->engEx = $row['engEx'];
                $temp->vietEx = $row['vietEx'];
                $temp->audioEx = $row['audioEx'];
                $temp->id = $row['id'];
                $temp->picture = $row['picture'];


                $listWord[] = $temp;
            }

            $connection->close();

            return $listWord;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }

    function findWordID($id) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();

            $sql = "select* from Word where ID =" . $id;
            $result = $connection->executeQuery($sql);
            $wordResult = new Word();
            while ($row = mysql_fetch_array($result)) {
                $wordResult = new Word();
                $wordResult->audio = $row['audio'];
                $wordResult->id_Lesson = $row['id_Lesson'];
                $wordResult->engName = $row['engName'];
                $wordResult->vietName = $row['vietName'];
                $wordResult->engEx = $row['engEx'];
                $wordResult->vietEx = $row['vietEx'];
                $wordResult->audioEx = $row['audioEx'];
                $wordResult->id = $row['id'];
                $wordResult->picture = $row['picture'];
            }

            $connection->close();

            return $wordResult;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }

}